<include file="__THEME__/public_header" />
<div id="page-wrap">
  <div class="reg-wrap">
    <div class="reg-tab-menu">
      <ul>
        <li><a href="{:U('public/Passport/findPassword', array('t'=>'email'))}" 
          <eq name="type" value="email">class="cur"</eq>
          >邮箱密码</a></li>
        <li><a href="{:U('public/Passport/findPassword', array('t'=>'mobile'))}" 
          <eq name="type" value="mobile">class="cur"</eq>
          >手机密码</a></li>
      </ul>
    </div>
    <div class="reg-main">
      <php>if($type === 'email'):</php>
      <dl class="search-find">
        <dt class="mb20 clearfix">
          <form id="find_password_form" method="POST" action="{:U('public/Passport/doFindPasswordByEmail')}">
            <input id="pwd_input" name="email" type="text" class="s-txt left"  style="width:450px;height:24px;line-height:24px; padding:5px;border:#858585 1px solid;" />
            <a class="btn-green-big left ml5" id="send" href=""><span>{:L('PUBLIC_SEND')}</span></a>
          </form>
        </dt>
        <dd>请输入您注册时用的EMAIL，我们会将该密码重置邮件发送至该邮箱。</dd>
        <dd>{:L('PUBLIC_PASSWORD_EMAIL_TIPS')}</dd>
      </dl>
      <php>elseif($type === 'mobile'):</php>
      <form id="find_password_form" method="post" action="{:U('public/Passport/doFindPasswordByMobile')}">
        <dl class="item phone-find">
          <dd class="">
            <div class="form-tt">手机号</div>
            <div class="form-row clearfix">
              <input id="phone" event-node="phone" name="phone" checkurl="{:U('public/Passport/isPhoneAvailable')}" autocomplete="off" type="text" value="" class="s-txt left"  style="width:450px;height:24px; float:left;line-height:24px; padding:5px;border:#858585 1px solid;" />
            </div>
          </dd>
          <dd class="">
            <div class="form-tt">图形码</div>
            <div class="form-row clearfix">
              <input class="s-txt" id="image-code-input" style="width: 325px;height: 24px;float: left;line-height: 24px;padding: 5px;border: #858585 1px solid;" type="text">
              <img id="image-code-button" style="width: 120px;height: 36px;margin-left: 5px;cursor: pointer;" src="__ROOT__/public/captcha.php" alt="图像验证码" title="点击刷新" data-url="__ROOT__/public/captcha.php?time=%d">
            </div>
            <script type="text/javascript">
              $('#image-code-button').on('click', function(event) {
                event.preventDefault();
                var time = (new Date()).getTime()
                var src  = $(this).data('url').replace(/\%d/ig, time);
                $(this).attr('src', src);
              });
            </script>
          </dd>
          <dd class="">
            <div class="form-tt">验证码</div>
            <div class="form-row clearfix">
              <input name="regCode" type="text" id="regCode" tel="" event-node="input_reg_code" checkurl="{:U('public/Passport/isRegCodeAvailable')}" class="s-txt" style="width:325px;height:24px; float:left;line-height:24px; padding:5px;border:#858585 1px solid;" />
              <a class="get-phone-code" id="reg_msg" style="background: #0096e5;color: #fff;" href=""><span>获取短信验证码</span></a>
              <div class="captcha-tips"> </div>
              <div class="txt-info" id="reg_msg_tip" style="display:none;">验证码已发送到您的手机，30分钟内输入有效，请勿泄露。</div>
            </div>
          </dd>
          <dd>
            <div class="form-tt">&nbsp;</div>
            <div class="form-row"> <a class="btn-green-big" id="send" href=""><span>{:L('PUBLIC_SEND')}</span></a> </div>
          </dd>
        </dl>
      </form>
      <php>endif;</php>
    </div>
  </div>
</div>
<script type="text/javascript" src="__THEME__/js/jquery.form.js"></script> 
<script type="text/javascript" src="__THEME__/js/module.form.js"></script> 
<script type="text/javascript">
<?php if($type === 'email'): ?>
$(document).ready(function() {
    $('#find_password_form').submit(function(){
        $(this).ajaxSubmit({
            beforeSubmit: checkPwdForm,
            dataType: "json",
            success: pwdCallback
        }); 
        return false; 
    });
    // 检查数据正确性
    var checkPwdForm = function() {
		var pwdText = $("#pwd_input").val();
		pwdText = $.trim(pwdText);
		if(pwdText == "") {
			ui.error("请输入你的邮箱地址");
			return false;
		}
		var eMailReg = /[_a-zA-Z\d\-\.]+(@[_a-zA-Z\d\-\.]+\.[_a-zA-Z\d\-]+)+$/i;
		if(!eMailReg.test(pwdText)) {
			ui.error("邮箱格式不正确");
			return false;
		}
    };
    // 回调函数
    var pwdCallback = function(msg) {
    	if(msg.status == 1) {
    		ui.success(msg.info);
    		return false;
    	} else {
    		ui.error(msg.info);
    		return false;
    	}
    };
});
<?php endif; ?>

var lock = 0;
var timefun = '';
var timenum = 0;
var regMsg = function() {
	var mobile = $.trim($('#phone').val());
	if (mobile === '') {
		ui.error('手机号不能为空');
		return false;
	}
	if( !(/^[1][358]\d{9}$/.test(mobile)) ){
		ui.error('请填写正确的11位手机号');
		return false;
	}
	if (lock == 1) {
		return false;
	} else {
		timenum = 60;
		clearInterval(timefun);
		lock = 1;
	}
	$.post(U('public/Passport/sendPasswordCode'), {mobile:mobile, verify: $('#image-code-input').val()}, function(res) {
		if (res.status == 0) {
			lock = 0;
			ui.error(res.info);
		} else {
			$('#reg_msg_tip').show();
			timefun = setInterval(timeout, 1000);
			ui.success('短信发送成功，请耐心等待');
		}
	},'json');
}
var timeout = function() {
	timenum -= 1;
	if (timenum < 0) {
		clearInterval(timefun);
		timefun = '';
		lock = 0;
		$('#reg_msg_tip').hide();
		$('#reg_msg').find('span').text('获取短信验证码');
		return;
	}
	$('#reg_msg').find('span').text('('+timenum+')获取短信验证码');
}

$(function() {
	var valChange = function() {
		$('#regCode').attr('tel', $.trim($('#phone').val()));
	};
	// 浏览器的输入的兼容性
    if($.browser.msie && parseInt($.browser.version) < 9) {
        $(this).bind("propertychange", function() {
            valChange();
        });
    } else {
        $(this).bind("input", function() {
            valChange();
        });
    }
});

<?php if($type === 'mobile'): ?>
$(function() {
  /* 获取验证码 */
  // $('#reg_msg').on('click', function(event) {
  //   event.preventDefault();
  //   regMsg();
  // });

  /* 设置状态 */
  var getCodeStatus = function(time) {
    var but = $('.get-phone-code');
    if (time <= 0) {
      but.removeAttr('disabled').text('获取短信验证码').attr('style', 'background: #0096e5;color: #fff;');
      $('#reg_msg_tip').hide();
      return false;
    } else if (but.attr('style')) {
      but.removeAttr('style');
    };
    but.attr('disabled', 'disabled').text(time + '秒后重新获取');
    $('#reg_msg_tip').show();
    setTimeout(function() {
      getCodeStatus(time - 1);
    }, 1000);
  };

  /* 获取验证码 */
  $('.get-phone-code').on('click', function(event) {
    event.preventDefault();
    if ($(this).attr('disabled')) {
      return false;
    };
    $.post('{:U('public/Passport/sendPasswordCode')}', {
      mobile: $.trim($('#phone').val()),
      verify: $('#image-code-input').val()
    }, function(data) {
      if (data.status == 1) {
        ui.success(data.info);
        getCodeStatus(10);
        return false;
      };
      ui.error(data.info);
      return false;
    }, 'json');
  });

  $('#find_password_form').submit(function() {
    $(this).ajaxSubmit({
      beforeSubmit: function () {
        window.tips.setSubmit(1);
        var oCollection = $('#find_password_form')[0].elements;
        var nL = oCollection.length;
        var bValid = true;
        var dFirstError;

        for(var i = 0; i < nL; i++) {
          var dInput = oCollection[i];
          var sName = dInput.name;
          // 如果没有事件节点，则直接略过检查
          if(!sName || !dInput.getAttribute("event-node")) {
            continue;
          }

          ("function" === typeof(dInput.onblur)) && dInput.onblur();

          if(!dInput.bIsValid) {
            bValid = false;
            if(dInput.type != 'hidden') {
              dFirstError = dFirstError || dInput;
            }
          }
        }

        dFirstError && dFirstError.focus();

        return bValid;
      },
      success: function(res) {
      	if (res.status) {
      		// ui.success(res.info);
      		// setTimeout(function() {
      			location.href = res.data.url;
      		// }, 1500);
      	} else {
      		ui.error(res.info);
      	}
      },
      dataType: 'json'
    });
    return false;
  });
});
<?php endif; ?>
</script>
<script>
$(function() {
  $('#send').on('click', function(event) {
    event.preventDefault();
    $('#find_password_form').submit();
  });
});
</script>
<include file="__THEME__/public_footer" />